package com.jash.designpack2;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.support.v8.renderscript.Allocation;
import android.support.v8.renderscript.Element;
import android.support.v8.renderscript.RenderScript;
import android.support.v8.renderscript.ScriptIntrinsicBlur;
import android.widget.LinearLayout;

public class AlbumActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_album);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        RenderScript script = RenderScript.create(this);
        ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(script, Element.RGBA_8888(script));
        blur.setRadius(1);
        Bitmap src = BitmapFactory.decodeResource(getResources(), R.mipmap.img);
        Bitmap target = Bitmap.createBitmap(src.getWidth(), src.getHeight(), Bitmap.Config.ARGB_8888);
        Allocation in = Allocation.createFromBitmap(script, src);
        blur.setInput(in);
        Allocation out = Allocation.createFromBitmap(script, target);
        blur.forEach(out);
        out.copyTo(target);
        LinearLayout linear = (LinearLayout) findViewById(R.id.linear);
        linear.setBackgroundDrawable(new BitmapDrawable(target));
    }
}
